package com.wudl.govern.controller;

import com.wudl.common.api.CommonResult;

import com.wudl.govern.domain.MetaForeignkeyHistory;
import com.wudl.govern.service.MetaForeignkeyHistoryService;
import com.wudl.govern.vo.MetaForeignkeyHistoryVO;
import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;
import java.util.ArrayList;

/**
 * meta_foreignkey_history Service
 *
 * @author wudl
 */
@Api
@RestController
@RequestMapping("/metaForeignkeyHistory")
public class MetaForeignkeyHistoryController {

    @Autowired
    private MetaForeignkeyHistoryService metaForeignkeyHistoryService;

    /**
     * 分页查询
     */
    @PostMapping("/page")
    public CommonResult<List<MetaForeignkeyHistoryVO>> page(@RequestBody MetaForeignkeyHistoryVO pageVO, @RequestParam Integer page, @RequestParam Integer size) {

        List<MetaForeignkeyHistoryVO> MetaForeignkeyHistoryVoList = new ArrayList<>();
  // 拷贝结果
        List<MetaForeignkeyHistory> MetaForeignkeyHistoryList = metaForeignkeyHistoryService.page(page, size);

        for (MetaForeignkeyHistory metaForeignkeyHistoryTmp:MetaForeignkeyHistoryList )
        {
            MetaForeignkeyHistoryVO metaForeignkeyHistoryVO = new MetaForeignkeyHistoryVO();
            BeanUtil.copyProperties(metaForeignkeyHistoryTmp, MetaForeignkeyHistoryVO.class);
            MetaForeignkeyHistoryVoList.add(metaForeignkeyHistoryVO);
        }
        return CommonResult.success(MetaForeignkeyHistoryVoList);


    }

    /**
     * 查询详情
     */
    @GetMapping("/get/{id}")
    public CommonResult<MetaForeignkeyHistoryVO> get(@PathVariable Integer id) {
        MetaForeignkeyHistory entity = metaForeignkeyHistoryService.getById(id);
        return CommonResult.success(BeanUtil.copyProperties(entity, MetaForeignkeyHistoryVO.class));
    }

    /**
     * 新增
     */
    @PostMapping("/add")
    public CommonResult<Void> add(@RequestBody MetaForeignkeyHistoryVO addVO) {
        metaForeignkeyHistoryService.save(BeanUtil.copyProperties(addVO, MetaForeignkeyHistory.class));
        return CommonResult.success();
    }

    /**
     * 编辑
     */
    @PutMapping("/edit")
    public CommonResult<Void> edit(@RequestBody MetaForeignkeyHistoryVO editVO) {
        metaForeignkeyHistoryService.updateById(BeanUtil.copyProperties(editVO, MetaForeignkeyHistory.class));
        return CommonResult.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public CommonResult<Void> delete(@PathVariable Integer id) {
        metaForeignkeyHistoryService.removeById(id);
        return CommonResult.success();
    }

}
